﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace WindowsApplication1
{
    public enum CardTypes
    {
        A = 1,
        Two = 2,
        Three = 3,
        Four = 4,
        Five = 5,
        Six = 6,
        Seven = 7,
        Eight = 8,
        Nine = 9,
        T = 10,
        J = 11,
        Q = 12,
        K = 13
    }

    public enum Suits
    {
        H = 1,
        D = 2,
        C = 3,
        S = 4
    }

    public class Card
    {
        public CardTypes CardType { get; set; }
        public int Value { get; set; }
        public Suits Suit { get; set; }

        public Card() { }

        public string FaceName
        {
            get { return Value.ToString() + Suit.ToString() + "-" + CardType.ToString(); }
        }

        public string NumName
        {
            get { return Value.ToString() + Suit.ToString() + "-" + (int)CardType; }
        }

        public Card[] createShoe(int NumOfDecks)
        {
            int CardNumber = 0;
            Card[] FullShoe = new Card[NumOfDecks * 52];
            for (int d = 0; d < NumOfDecks; d++)
                for (int c = 1; c < 14; c++)
                    for (int suit = 1; suit <= 4; suit++)
                    {
                        Card tempcard = new Card() { CardType = (CardTypes)c, Value = c, Suit = (Suits)suit };
                        if (c >= 10)
                        {
                            tempcard.Value = 10;
                            FullShoe[CardNumber] = tempcard;
                        }
                        else
                        {
                            FullShoe[CardNumber] = tempcard;
                        }
                        CardNumber++;
                    }
            return FullShoe;
        }

        public Card[] shuffleDeck(Card[] FullShoe)
        {
            int NumberOfCards = FullShoe.Length - 1;
            Card temp = null;
            RNGCryptoServiceProvider rnd = new RNGCryptoServiceProvider();
            int PRand = 0;

            for (int x = 1; x <= NumberOfCards; x++)
            {
                //Swap x with random position...
                PRand = (GetNextInt32(rnd) % NumberOfCards);
                temp = FullShoe[x];
                FullShoe[x] = FullShoe[PRand];
                FullShoe[PRand] = temp;
            }
            return FullShoe;
        }

        static int GetNextInt32(RNGCryptoServiceProvider rnd)
        {
            byte[] randomInt = new byte[4];
            rnd.GetBytes(randomInt);
            return Convert.ToInt32(randomInt[0]);
        }
    }
}
